<extend name="./public/frame.html"/>
<block name="content">
    <blockquote class="layui-elem-quote search">
        <div class="layui-inline">
            <select id="classification_id" name="classification_id" class="layui-input"lay-filter="classification_id" style="width: 120px;">
                <option value="">商品分类</option>
                <?php foreach($cate as $key=>$value):?>
                <option value="<?php echo $key;?>"><?php echo $value;?></option>
                <?php endforeach;?>
            </select>
        </div>
        <div class="layui-inline">
            <input type="text" name="commodity_name" id="commodity_name" placeholder="商品名称" class="layui-input">
        </div>
        <div class="layui-inline">
            <input type="text" name="user_phone" id="user_phone" placeholder="用户手机号" class="layui-input">
        </div>
        <div class="layui-inline">
            <input type="text" class="layui-input" id="start_time" placeholder="开始时间">
        </div>
        <div class="layui-inline">
            <input type="text" class="layui-input" id="end_time" placeholder="结束时间">
        </div>
        <div class="layui-inline">
            <select id="is_grant" name="is_grant" class="layui-input"lay-filter="is_grant" style="width: 120px;">
                <option value="">状态</option>
                <option value="1">已充值</option>
                <option value="0">待充值</option>
            </select>
        </div>
        <div class="layui-inline">
            <button class="layui-btn" data-type="search">搜索</button>
        </div>
    </blockquote>

    <table class="layui-table" lay-data="{width:'auto', height:'auto', url:'{:url('Point/indexChange')}', page: true, limit: 10, id:'test'}" lay-filter="test">
        <thead>
        <tr>
            <th lay-data="{checkbox:true, fixed: true}"></th>
            <th lay-data="{field:'id', width:100,align:'center', fixed: true, sort: true}">订单ID</th>
            <th lay-data="{field:'order_sn', width:200,align:'center', fixed: true, sort: true}">订单编号</th>
            <th lay-data="{field:'classification_name', width:200,align:'center'}">分类名称</th>
            <th lay-data="{field:'user_phone', width:200,align:'center'}">用户手机号</th>
            <th lay-data="{field:'classification_name', width:200,align:'center'}">分类</th>
            <th lay-data="{field:'commodity_name', width:300,align:'center'}">商品名称</th>
            <th lay-data="{field:'recharge_phone', width:200,align:'center'}">充值手机号</th>
            <th lay-data="{field:'consumption_points', width:200,align:'center'}">兑换积分</th>
            <th lay-data="{field:'remark', width:200,align:'center'}">备注留言</th>
            <th lay-data="{field:'add_time', width:200,align:'center'}">兑换时间</th>
            <th lay-data="{field:'is_grant', width:200,align:'center'}">订单状态</th>
            <th lay-data="{field:'admin_name', width:200,align:'center'}">处理人</th>
            <th lay-data="{field:'update_time', width:200,align:'center'}">处理时间</th>
            <th lay-data="{fixed:'right', toolbar: '#barDemo', width:200, align:'center'}">操作</th>
        </tr>
        </thead>
    </table>
    <script type="text/html" id="barDemo">
        {{#if(d.is_grant == '已充值'){}}
        <a class="layui-btn layui-btn-xs" style="width: 50px;cursor:default">已充值</a>
        {{#}else{}}
        <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="rechargeChange" style="width: 50px">待充值</a>
        {{#}}}
    </script>
    <script>
        layui.use(['form','table','laydate'], function () {
            var table = layui.table,form = layui.form,laydate = layui.laydate;
            laydate.render({
                elem: '#start_time' //指定元素
            });
            laydate.render({
                elem: '#end_time' //指定元素
            });
            table.on('tool(test)', function (obj) {
                var data = obj.data;
                var id = data.id;

                if (obj.event === 'rechargeChange') {
                    layer.confirm('确定已充值吗?',function(index){
                        var url = '{:url("/admin/Point/rechargeChange","id=")}' + id
                        $.get(url,function(data){
                            if(data.status == 1){
                                layer.msg('充值成功',{'icon':1});
                                window.location.reload();
                            }else{
                                layer.msg('充值失败',{'icon':2});
                            }
                        },'json')
                        layer.close(index);
                    })
                }
            });
            //搜索
            $('.layui-btn').on('click', function () {
                var classification_id = $("#classification_id").val();
                var commodity_name = $("#commodity_name").val();
                var start_time = $("#start_time").val();
                var end_time = $("#end_time").val();
                var is_grant = $("#is_grant").val();
                var user_phone = $("#user_phone").val();
                table.reload('test', {
                    url: '/admin/Point/indexChange', where: {
                        "classification_id": classification_id,
                        "commodity_name": commodity_name,
                        "start_time": start_time,
                        "end_time": end_time,
                        "is_grant": is_grant,
                        "user_phone" :user_phone
                    }
                });
            })
        });

    </script>
</block>
